package cn.edu.gdpt.mobile213.mobile2121606097wjc0503;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class PartRVAdapter extends RecyclerView.Adapter<PartRVAdapter.ViewHolder>{
   int[] partIDs;
   String[] partNames;
   public PartRVAdapter(int[] partIDs,String[] partNames){
       this.partIDs=partIDs;
       this.partNames=partNames;
   }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView ivPart;
        TextView tvPart;
        public ViewHolder(@NonNull View itemView){
            super(itemView);
            ivPart=itemView.findViewById(R.id.ivitemPart);
            tvPart=itemView.findViewById(R.id.tvitemPart);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       View view= LayoutInflater.from(parent.getContext()).inflate(
       R.layout.item_rv_main_part,parent,false);
       return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.ivPart.setImageResource(partIDs[position]);
        holder.tvPart.setText(partNames[position]);
    }

    @Override
    public int getItemCount() {
        return partIDs.length;
    }
}
